
package com.yuan.servlet;

import com.yuan.hibernate.员工信息表;
import com.yuan.hibernate.员工信息表DAO;
import com.yuan.hibernate.考勤表;
import com.yuan.hibernate.考勤表DAO;
import com.yuan.prefence.PreferenceKeys;
import com.yuan.util.JsonUtils;
import com.yuan.util.TimeUtil;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ischeckedintoday extends BaseHttpServlet {
    private 考勤表DAO m考勤表DAO = null;
    private 员工信息表 m员工信息表 = null;
    private 员工信息表DAO m员工信息表DAO = null;

    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        super.doGet(request, response);
        int userid = Integer.parseInt(request.getParameter("userid"));
        m员工信息表DAO = new 员工信息表DAO();
        m考勤表DAO = new 考勤表DAO();
        m员工信息表 = m员工信息表DAO.findById(userid);
        @SuppressWarnings("unchecked")
        List<考勤表> tempList = m考勤表DAO.findBy职工姓名(m员工信息表.get姓名());
        for (考勤表 temp : tempList) {
            if (temp.getId().get日期().startsWith(TimeUtil.getNowTime().substring(0, 10))
                    && temp.get备注().contains(PreferenceKeys.CHECKINTIME))
            {
                List<考勤表> list = new ArrayList<考勤表>();
                list.add(temp);
                mResponse = JsonUtils.getFromList(list);
                mResponse = mResponse.replace("{\"id\":", "");
                mResponse = mResponse.replace("},\"位置\"", ",\"位置\"");
            }
        }
        if (mResponse == null)
        {
            mResponse = "尚未签到";
        }
        closeAndClear();

    }

    @Override
    protected synchronized void closeAndClear() {
        m考勤表DAO = null;
        m员工信息表 = null;
        m员工信息表DAO = null;
        super.closeAndClear();
    }
}
